package com.qf.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ESConfig {

    @Value("${es.host}")
    private String host;

    @Value("${es.port}")
    private Integer port;

    @Bean
    public RestHighLevelClient restHighLevelClient() {

        // 1 封装es的ip和端口
        HttpHost httpHost = new HttpHost(host, port);

        // 2.构建对象
        RestClientBuilder builder = RestClient.builder(httpHost);

        // 3.创建es客户端
        RestHighLevelClient client = new RestHighLevelClient(builder);
        return client;
    }
}
